<!DOCTYPE html><html><head><title>2020年04期在线JS高级（第一周作业）</title><meta charset='utf-8'><link href='https://cdn.maxiang.io/res-min/themes/marxico.css' rel='stylesheet'><style>
.note-content  {font-family: "Helvetica Neue", Arial, "Hiragino Sans GB", STHeiti, "Microsoft YaHei", "WenQuanYi Micro Hei", SimSun, Song, sans-serif;}

</style></head><body><div id='preview-contents' class='note-content'>
                        
                    

<h3 id="2020年04期在线js高级第一周作业">2020年04期在线JS高级（第一周作业）</h3>

<h4 id="一变量提升的作业">一、变量提升的作业</h4>

<p><img longdesc="./1594549120123.png" alt="Alt text" title="" type="image/png" src="" class=""> <br>
至少看完第一个视频再去做</p>

<p><strong>1</strong></p>

<pre class="prettyprint hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-built_in">console</span>.log(a, b, c);
</div><div class="hljs-line"><span class="hljs-keyword">var</span> a = <span class="hljs-number">12</span>,
</div><div class="hljs-line">    b = <span class="hljs-number">13</span>,
</div><div class="hljs-line">    c = <span class="hljs-number">14</span>;
</div><div class="hljs-line"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fn</span>(<span class="hljs-params">a</span>) </span>{
</div><div class="hljs-line">    <span class="hljs-built_in">console</span>.log(a, b, c);
</div><div class="hljs-line">    a = <span class="hljs-number">100</span>;
</div><div class="hljs-line">    c = <span class="hljs-number">200</span>;
</div><div class="hljs-line">    <span class="hljs-built_in">console</span>.log(a, b, c);
</div><div class="hljs-line">}
</div><div class="hljs-line">b = fn(<span class="hljs-number">10</span>);
</div><div class="hljs-line"><span class="hljs-built_in">console</span>.log(a, b, c);
</div></code></pre>

<p><strong>2</strong></p>



<pre class="prettyprint hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-keyword">var</span> i = <span class="hljs-number">0</span>;
</div><div class="hljs-line"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">A</span>(<span class="hljs-params"></span>) </span>{
</div><div class="hljs-line">    <span class="hljs-keyword">var</span> i = <span class="hljs-number">10</span>;
</div><div class="hljs-line">    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">x</span>(<span class="hljs-params"></span>) </span>{
</div><div class="hljs-line">        <span class="hljs-built_in">console</span>.log(i);
</div><div class="hljs-line">    }
</div><div class="hljs-line">    <span class="hljs-keyword">return</span> x;
</div><div class="hljs-line">}
</div><div class="hljs-line"><span class="hljs-keyword">var</span> y = A();
</div><div class="hljs-line">y();
</div><div class="hljs-line"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">B</span>(<span class="hljs-params"></span>) </span>{
</div><div class="hljs-line">    <span class="hljs-keyword">var</span> i = <span class="hljs-number">20</span>;
</div><div class="hljs-line">    y();
</div><div class="hljs-line">}
</div><div class="hljs-line">B();
</div></code></pre>

<p><strong>3</strong></p>

<pre class="prettyprint hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-keyword">var</span> a=<span class="hljs-number">1</span>;
</div><div class="hljs-line"><span class="hljs-keyword">var</span> obj ={
</div><div class="hljs-line">   <span class="hljs-attr">name</span>:<span class="hljs-string">"tom"</span>
</div><div class="hljs-line">}
</div><div class="hljs-line"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fn</span>(<span class="hljs-params"></span>)</span>{
</div><div class="hljs-line">   <span class="hljs-keyword">var</span> a2 = a;
</div><div class="hljs-line">   obj2 = obj;
</div><div class="hljs-line">   a2 =a;
</div><div class="hljs-line">   obj2.name =<span class="hljs-string">"jack"</span>;
</div><div class="hljs-line">}
</div><div class="hljs-line">fn();
</div><div class="hljs-line"><span class="hljs-built_in">console</span>.log(a);
</div><div class="hljs-line"><span class="hljs-built_in">console</span>.log(obj);
</div></code></pre>

<p><strong>4</strong></p>

<pre class="prettyprint hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-keyword">var</span> a = <span class="hljs-number">1</span>;
</div><div class="hljs-line"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fn</span>(<span class="hljs-params">a</span>)</span>{
</div><div class="hljs-line">    <span class="hljs-built_in">console</span>.log(a)
</div><div class="hljs-line">    <span class="hljs-keyword">var</span> a = <span class="hljs-number">2</span>;
</div><div class="hljs-line">    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">a</span>(<span class="hljs-params"></span>)</span>{}
</div><div class="hljs-line">}
</div><div class="hljs-line">fn(a);
</div></code></pre>

<p><strong>5</strong></p>

<pre class="prettyprint hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-built_in">console</span>.log(a); 
</div><div class="hljs-line"><span class="hljs-keyword">var</span> a=<span class="hljs-number">12</span>; 
</div><div class="hljs-line"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fn</span>(<span class="hljs-params"></span>)</span>{
</div><div class="hljs-line">    <span class="hljs-built_in">console</span>.log(a); 
</div><div class="hljs-line">    <span class="hljs-keyword">var</span> a=<span class="hljs-number">13</span>;   
</div><div class="hljs-line">}
</div><div class="hljs-line">fn();   
</div><div class="hljs-line"><span class="hljs-built_in">console</span>.log(a);
</div><div class="hljs-line"><wbr>
</div><div class="hljs-line">----
</div><div class="hljs-line"><wbr>
</div><div class="hljs-line"><span class="hljs-built_in">console</span>.log(a); 
</div><div class="hljs-line"><span class="hljs-keyword">var</span> a=<span class="hljs-number">12</span>;
</div><div class="hljs-line"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fn</span>(<span class="hljs-params"></span>)</span>{
</div><div class="hljs-line">    <span class="hljs-built_in">console</span>.log(a);
</div><div class="hljs-line">    a=<span class="hljs-number">13</span>;
</div><div class="hljs-line">}
</div><div class="hljs-line">fn();
</div><div class="hljs-line"><span class="hljs-built_in">console</span>.log(a);
</div><div class="hljs-line"><wbr>
</div><div class="hljs-line">----
</div><div class="hljs-line"><wbr>
</div><div class="hljs-line"><span class="hljs-built_in">console</span>.log(a);
</div><div class="hljs-line">a=<span class="hljs-number">12</span>;
</div><div class="hljs-line"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fn</span>(<span class="hljs-params"></span>)</span>{
</div><div class="hljs-line">    <span class="hljs-built_in">console</span>.log(a);
</div><div class="hljs-line">    a=<span class="hljs-number">13</span>;   
</div><div class="hljs-line">}
</div><div class="hljs-line">fn();
</div><div class="hljs-line"><span class="hljs-built_in">console</span>.log(a);
</div></code></pre>

<p><strong>6</strong></p>



<pre class="prettyprint hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-keyword">var</span> foo=<span class="hljs-string">'hello'</span>; 
</div><div class="hljs-line">(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">foo</span>)</span>{
</div><div class="hljs-line">   <span class="hljs-built_in">console</span>.log(foo);
</div><div class="hljs-line">   <span class="hljs-keyword">var</span> foo=foo||<span class="hljs-string">'world'</span>;
</div><div class="hljs-line">   <span class="hljs-built_in">console</span>.log(foo);
</div><div class="hljs-line">})(foo);
</div><div class="hljs-line"><span class="hljs-built_in">console</span>.log(foo);
</div></code></pre>

<p><strong>7</strong></p>

<pre class="prettyprint hljs-dark"><code class="language-javascript hljs"><div class="hljs-line">{
</div><div class="hljs-line">    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params"></span>) </span>{}
</div><div class="hljs-line">    foo = <span class="hljs-number">1</span>;
</div><div class="hljs-line">}
</div><div class="hljs-line"><span class="hljs-built_in">console</span>.log(foo);
</div><div class="hljs-line"><wbr>
</div><div class="hljs-line">----
</div><div class="hljs-line"><wbr>
</div><div class="hljs-line">{
</div><div class="hljs-line">    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params"></span>) </span>{}
</div><div class="hljs-line">    foo = <span class="hljs-number">1</span>;
</div><div class="hljs-line">    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params"></span>) </span>{}
</div><div class="hljs-line">}
</div><div class="hljs-line"><span class="hljs-built_in">console</span>.log(foo);
</div><div class="hljs-line"><wbr>
</div><div class="hljs-line">----
</div><div class="hljs-line"><wbr>
</div><div class="hljs-line">{
</div><div class="hljs-line">    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params"></span>) </span>{}
</div><div class="hljs-line">    foo = <span class="hljs-number">1</span>;
</div><div class="hljs-line">    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span>(<span class="hljs-params"></span>) </span>{}
</div><div class="hljs-line">    foo = <span class="hljs-number">2</span>;
</div><div class="hljs-line">}
</div><div class="hljs-line"><span class="hljs-built_in">console</span>.log(foo);
</div></code></pre>

<p><strong>8</strong></p>

<p><img longdesc="./1594549323642.png" alt="Alt text" title="" type="image/png" src="" class=""></p>

<h4 id="二数据类型和基础知识作业">二、数据类型和基础知识作业</h4>

<p><strong>1</strong></p>

<pre class="prettyprint hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-keyword">let</span> result = <span class="hljs-number">100</span> + <span class="hljs-literal">true</span> + <span class="hljs-number">21.2</span> + <span class="hljs-literal">null</span> + <span class="hljs-literal">undefined</span> + <span class="hljs-string">"Tencent"</span> + [] + <span class="hljs-literal">null</span> + <span class="hljs-number">9</span> + <span class="hljs-literal">false</span>;
</div><div class="hljs-line"><span class="hljs-built_in">console</span>.log(result);
</div></code></pre>

<p><strong>2</strong></p>

<pre class="prettyprint hljs-dark"><code class="language-javascript hljs"><div class="hljs-line">{}+<span class="hljs-number">0</span>?alert(<span class="hljs-string">'ok'</span>):alert(<span class="hljs-string">'no'</span>);
</div><div class="hljs-line"><span class="hljs-number">0</span>+{}?alert(<span class="hljs-string">'ok'</span>):alert(<span class="hljs-string">'no'</span>);
</div></code></pre>

<p><strong>3</strong></p>

<pre class="prettyprint hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-keyword">let</span> res = <span class="hljs-built_in">Number</span>(<span class="hljs-string">'12px'</span>);
</div><div class="hljs-line"><span class="hljs-keyword">if</span>(res===<span class="hljs-number">12</span>){
</div><div class="hljs-line">    alert(<span class="hljs-number">200</span>);
</div><div class="hljs-line">}<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(res===<span class="hljs-literal">NaN</span>){
</div><div class="hljs-line">    alert(<span class="hljs-literal">NaN</span>);
</div><div class="hljs-line">}<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(<span class="hljs-keyword">typeof</span> res===<span class="hljs-string">'number'</span>){
</div><div class="hljs-line">    alert(<span class="hljs-string">'number'</span>);
</div><div class="hljs-line">}<span class="hljs-keyword">else</span>{
</div><div class="hljs-line">    alert(<span class="hljs-string">'Invalid Number'</span>);
</div><div class="hljs-line">}
</div></code></pre>

<p><strong>4</strong></p>

<pre class="prettyprint hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-keyword">let</span> arr = [<span class="hljs-number">27.2</span>,<span class="hljs-number">0</span>,<span class="hljs-string">'0013'</span>,<span class="hljs-string">'14px'</span>,<span class="hljs-number">123</span>];
</div><div class="hljs-line">arr = arr.map(<span class="hljs-built_in">parseInt</span>);
</div><div class="hljs-line"><span class="hljs-built_in">console</span>.log(arr);
</div></code></pre>

<h4 id="三闭包作用域的作业">三、闭包作用域的作业</h4>

<p><strong>1</strong></p>

<pre class="prettyprint hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-keyword">var</span> a = <span class="hljs-number">10</span>,
</div><div class="hljs-line">    b = <span class="hljs-number">11</span>,
</div><div class="hljs-line">    c = <span class="hljs-number">12</span>;
</div><div class="hljs-line"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">test</span>(<span class="hljs-params">a</span>) </span>{
</div><div class="hljs-line">    a = <span class="hljs-number">1</span>;
</div><div class="hljs-line">    <span class="hljs-keyword">var</span> b = <span class="hljs-number">2</span>;
</div><div class="hljs-line">    c = <span class="hljs-number">3</span>;
</div><div class="hljs-line">}
</div><div class="hljs-line">test(<span class="hljs-number">10</span>);
</div><div class="hljs-line"><span class="hljs-built_in">console</span>.log(a, b, c);
</div></code></pre>

<p><strong>2</strong></p>

<pre class="prettyprint hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-keyword">var</span> a = <span class="hljs-number">4</span>;
</div><div class="hljs-line"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">b</span>(<span class="hljs-params">x, y, a</span>) </span>{
</div><div class="hljs-line">    <span class="hljs-built_in">console</span>.log(a);
</div><div class="hljs-line">    <span class="hljs-built_in">arguments</span>[<span class="hljs-number">2</span>] = <span class="hljs-number">10</span>;
</div><div class="hljs-line">    <span class="hljs-built_in">console</span>.log(a);
</div><div class="hljs-line">}
</div><div class="hljs-line">a = b(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>);
</div><div class="hljs-line"><span class="hljs-built_in">console</span>.log(a);
</div></code></pre>

<p><strong>3</strong></p>

<pre class="prettyprint hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-keyword">var</span> a = <span class="hljs-number">9</span>;
</div><div class="hljs-line"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fn</span>(<span class="hljs-params"></span>) </span>{
</div><div class="hljs-line">    a = <span class="hljs-number">0</span>;
</div><div class="hljs-line">    <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">b</span>) </span>{
</div><div class="hljs-line">        <span class="hljs-keyword">return</span> b + a++;
</div><div class="hljs-line">    }
</div><div class="hljs-line">}
</div><div class="hljs-line"><span class="hljs-keyword">var</span> f = fn();
</div><div class="hljs-line"><span class="hljs-built_in">console</span>.log(f(<span class="hljs-number">5</span>));
</div><div class="hljs-line"><span class="hljs-built_in">console</span>.log(fn()(<span class="hljs-number">5</span>));
</div><div class="hljs-line"><span class="hljs-built_in">console</span>.log(f(<span class="hljs-number">5</span>));
</div><div class="hljs-line"><span class="hljs-built_in">console</span>.log(a);
</div></code></pre>

<p><strong>4</strong></p>

<pre class="prettyprint hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-keyword">var</span> test = (<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">i</span>) </span>{
</div><div class="hljs-line">    <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
</div><div class="hljs-line">        alert(i *= <span class="hljs-number">2</span>);
</div><div class="hljs-line">    }
</div><div class="hljs-line">})(<span class="hljs-number">2</span>);
</div><div class="hljs-line">test(<span class="hljs-number">5</span>);
</div></code></pre>

<p><strong>5</strong></p>

<pre class="prettyprint hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-keyword">var</span> x = <span class="hljs-number">4</span>;
</div><div class="hljs-line"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">func</span>(<span class="hljs-params"></span>) </span>{
</div><div class="hljs-line">    <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">y</span>) </span>{
</div><div class="hljs-line">        <span class="hljs-built_in">console</span>.log(y + (--x));
</div><div class="hljs-line">    }
</div><div class="hljs-line">}
</div><div class="hljs-line"><span class="hljs-keyword">var</span> f = func(<span class="hljs-number">5</span>);
</div><div class="hljs-line">f(<span class="hljs-number">6</span>);
</div><div class="hljs-line">func(<span class="hljs-number">7</span>)(<span class="hljs-number">8</span>);
</div><div class="hljs-line">f(<span class="hljs-number">9</span>);
</div><div class="hljs-line"><span class="hljs-built_in">console</span>.log(x);
</div></code></pre>

<p><strong>6</strong></p>

<pre class="prettyprint hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-keyword">var</span> x = <span class="hljs-number">5</span>,
</div><div class="hljs-line">    y = <span class="hljs-number">6</span>;
</div><div class="hljs-line"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">func</span>(<span class="hljs-params"></span>) </span>{
</div><div class="hljs-line">    x += y;
</div><div class="hljs-line">    func = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">y</span>) </span>{
</div><div class="hljs-line">        <span class="hljs-built_in">console</span>.log(y + (--x));
</div><div class="hljs-line">    };
</div><div class="hljs-line">    <span class="hljs-built_in">console</span>.log(x, y);
</div><div class="hljs-line">}
</div><div class="hljs-line">func(<span class="hljs-number">4</span>);
</div><div class="hljs-line">func(<span class="hljs-number">3</span>);
</div><div class="hljs-line"><span class="hljs-built_in">console</span>.log(x, y);
</div></code></pre>

<p><strong>7</strong></p>

<pre class="prettyprint hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fun</span>(<span class="hljs-params">n, o</span>) </span>{
</div><div class="hljs-line">    <span class="hljs-built_in">console</span>.log(o);
</div><div class="hljs-line">    <span class="hljs-keyword">return</span> {
</div><div class="hljs-line">        <span class="hljs-attr">fun</span>: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">m</span>) </span>{
</div><div class="hljs-line">            <span class="hljs-keyword">return</span> fun(m, n);
</div><div class="hljs-line">        }
</div><div class="hljs-line">    };
</div><div class="hljs-line">}
</div><div class="hljs-line"><span class="hljs-keyword">var</span> c = fun(<span class="hljs-number">0</span>).fun(<span class="hljs-number">1</span>);
</div><div class="hljs-line">c.fun(<span class="hljs-number">2</span>);
</div><div class="hljs-line">c.fun(<span class="hljs-number">3</span>);
</div></code></pre>

<p><strong>8 简述你对闭包的理解，以及其优缺点？</strong></p>

<p><strong>9 简述let和var的区别？</strong></p>

<p><strong>10 下面代码输出的结果是多少，为什么？如何改造一下，就能让其输出 20 10？</strong></p>

<pre class="prettyprint hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-keyword">var</span> b = <span class="hljs-number">10</span>;
</div><div class="hljs-line">(<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">b</span>(<span class="hljs-params"></span>) </span>{
</div><div class="hljs-line">    b = <span class="hljs-number">20</span>;
</div><div class="hljs-line">    <span class="hljs-built_in">console</span>.log(b);
</div><div class="hljs-line">})();
</div><div class="hljs-line"><span class="hljs-built_in">console</span>.log(b);
</div></code></pre>

<p><strong>11 实现函数fn，让其具有如下功能（百度二面）</strong></p>

<pre class="prettyprint hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-keyword">let</span> res = fn(<span class="hljs-number">1</span>,<span class="hljs-number">2</span>)(<span class="hljs-number">3</span>);
</div><div class="hljs-line"><span class="hljs-built_in">console</span>.log(res); <span class="hljs-comment">//=&gt;6  1+2+3</span>
</div></code></pre>

<p><strong>12 实现函数fn，让其具有如下功能（百度二面）</strong></p>

<pre class="prettyprint hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-comment">/* </span>
</div><div class="hljs-line"><span class="hljs-comment">    在函数式编程当中有一个很重要的概念就是函数组合， 实际上就是把处理数据的函数像管道一样连接起来， 然后让数据穿过管道得到最终的结果。 例如：</span>
</div><div class="hljs-line"><span class="hljs-comment">    const add1 = (x) =&gt; x + 1;</span>
</div><div class="hljs-line"><span class="hljs-comment">    const mul3 = (x) =&gt; x * 3;</span>
</div><div class="hljs-line"><span class="hljs-comment">    const div2 = (x) =&gt; x / 2;</span>
</div><div class="hljs-line"><span class="hljs-comment">    div2(mul3(add1(add1(0)))); //=&gt;3</span>
</div><div class="hljs-line"><span class="hljs-comment">​</span>
</div><div class="hljs-line"><span class="hljs-comment">    而这样的写法可读性明显太差了，我们可以构建一个compose函数，它接受任意多个函数作为参数（这些函数都只接受一个参数），然后compose返回的也是一个函数，达到以下的效果：</span>
</div><div class="hljs-line"><span class="hljs-comment">    const operate = compose(div2, mul3, add1, add1)</span>
</div><div class="hljs-line"><span class="hljs-comment">    operate(0) //=&gt;相当于div2(mul3(add1(add1(0)))) </span>
</div><div class="hljs-line"><span class="hljs-comment">    operate(2) //=&gt;相当于div2(mul3(add1(add1(2))))</span>
</div><div class="hljs-line"><span class="hljs-comment">​</span>
</div><div class="hljs-line"><span class="hljs-comment">    简而言之：compose可以把类似于f(g(h(x)))这种写法简化成compose(f, g, h)(x)，请你完成 compose函数的编写 </span>
</div><div class="hljs-line"><span class="hljs-comment">*/</span>
</div></code></pre>

<h4 id="四this的作业题">四、THIS的作业题</h4>

<p><strong>1</strong></p>

<pre class="prettyprint hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-keyword">var</span> num = <span class="hljs-number">10</span>;
</div><div class="hljs-line"><span class="hljs-keyword">var</span> obj = {
</div><div class="hljs-line">    <span class="hljs-attr">num</span>: <span class="hljs-number">20</span>
</div><div class="hljs-line">};
</div><div class="hljs-line">obj.fn = (<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">num</span>) </span>{
</div><div class="hljs-line">    <span class="hljs-keyword">this</span>.num = num * <span class="hljs-number">3</span>;
</div><div class="hljs-line">    num++;
</div><div class="hljs-line">    <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">n</span>) </span>{
</div><div class="hljs-line">        <span class="hljs-keyword">this</span>.num += n;
</div><div class="hljs-line">        num++;
</div><div class="hljs-line">        <span class="hljs-built_in">console</span>.log(num);
</div><div class="hljs-line">    }
</div><div class="hljs-line">})(obj.num);
</div><div class="hljs-line"><span class="hljs-keyword">var</span> fn = obj.fn;
</div><div class="hljs-line">fn(<span class="hljs-number">5</span>);
</div><div class="hljs-line">obj.fn(<span class="hljs-number">10</span>);
</div><div class="hljs-line"><span class="hljs-built_in">console</span>.log(num, obj.num);
</div></code></pre>

<p><strong>2</strong></p>

<pre class="prettyprint hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-keyword">let</span> obj = {
</div><div class="hljs-line">    <span class="hljs-attr">fn</span>: (<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
</div><div class="hljs-line">        <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
</div><div class="hljs-line">            <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>);
</div><div class="hljs-line">        }
</div><div class="hljs-line">    })()
</div><div class="hljs-line">};
</div><div class="hljs-line">obj.fn();
</div><div class="hljs-line"><span class="hljs-keyword">let</span> fn = obj.fn;
</div><div class="hljs-line">fn();
</div></code></pre>

<p><strong>3</strong></p>

<pre class="prettyprint hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-keyword">var</span> fullName = <span class="hljs-string">'language'</span>;
</div><div class="hljs-line"><span class="hljs-keyword">var</span> obj = {
</div><div class="hljs-line">    <span class="hljs-attr">fullName</span>: <span class="hljs-string">'javascript'</span>,
</div><div class="hljs-line">    <span class="hljs-attr">prop</span>: {
</div><div class="hljs-line">        <span class="hljs-attr">getFullName</span>: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
</div><div class="hljs-line">            <span class="hljs-keyword">return</span> <span class="hljs-keyword">this</span>.fullName;
</div><div class="hljs-line">        }
</div><div class="hljs-line">    }
</div><div class="hljs-line">};
</div><div class="hljs-line"><span class="hljs-built_in">console</span>.log(obj.prop.getFullName());
</div><div class="hljs-line"><span class="hljs-keyword">var</span> test = obj.prop.getFullName;
</div><div class="hljs-line"><span class="hljs-built_in">console</span>.log(test());
</div></code></pre>

<p><strong>4</strong></p>

<pre class="prettyprint hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-keyword">var</span> name = <span class="hljs-string">'window'</span>;
</div><div class="hljs-line"><span class="hljs-keyword">var</span> Tom = {
</div><div class="hljs-line">    <span class="hljs-attr">name</span>: <span class="hljs-string">"Tom"</span>,
</div><div class="hljs-line">    <span class="hljs-attr">show</span>: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
</div><div class="hljs-line">        <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>.name);
</div><div class="hljs-line">    },
</div><div class="hljs-line">    <span class="hljs-attr">wait</span>: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
</div><div class="hljs-line">        <span class="hljs-keyword">var</span> fun = <span class="hljs-keyword">this</span>.show;
</div><div class="hljs-line">        fun();
</div><div class="hljs-line">    }
</div><div class="hljs-line">};
</div><div class="hljs-line">Tom.wait();
</div></code></pre>

<p><strong>5</strong></p>

<pre class="prettyprint hljs-dark"><code class="language-javascript hljs"><div class="hljs-line"><span class="hljs-built_in">window</span>.val = <span class="hljs-number">1</span>;
</div><div class="hljs-line"><span class="hljs-keyword">var</span> json = {
</div><div class="hljs-line">    <span class="hljs-attr">val</span>: <span class="hljs-number">10</span>,
</div><div class="hljs-line">    <span class="hljs-attr">dbl</span>: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
</div><div class="hljs-line">        <span class="hljs-keyword">this</span>.val *= <span class="hljs-number">2</span>;
</div><div class="hljs-line">    }
</div><div class="hljs-line">}
</div><div class="hljs-line">json.dbl();
</div><div class="hljs-line"><span class="hljs-keyword">var</span> dbl = json.dbl;
</div><div class="hljs-line">dbl();
</div><div class="hljs-line">json.dbl.call(<span class="hljs-built_in">window</span>);
</div><div class="hljs-line">alert(<span class="hljs-built_in">window</span>.val + json.val);
</div></code></pre>

<p><strong>6</strong></p>

<pre class="prettyprint hljs-dark"><code class="language-javascript hljs"><div class="hljs-line">(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
</div><div class="hljs-line">    <span class="hljs-keyword">var</span> val = <span class="hljs-number">1</span>;
</div><div class="hljs-line">    <span class="hljs-keyword">var</span> json = {
</div><div class="hljs-line">        <span class="hljs-attr">val</span>: <span class="hljs-number">10</span>,
</div><div class="hljs-line">        <span class="hljs-attr">dbl</span>: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
</div><div class="hljs-line">            val *= <span class="hljs-number">2</span>;
</div><div class="hljs-line">        }
</div><div class="hljs-line">    };
</div><div class="hljs-line">    json.dbl();
</div><div class="hljs-line">    alert(json.val + val);
</div><div class="hljs-line">})();
</div></code></pre></div></body></html>